package com.sz.stock.controller;

import com.sz.stock.common.ResultBean;
import com.sz.stock.common.SmsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/tool")
public class ToolController {

    private SmsUtils smsUtils;

    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    public void setSmsUtils(SmsUtils smsUtils) {
        this.smsUtils = smsUtils;
    }

    @Autowired
    public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplate) {
        this.stringRedisTemplate = stringRedisTemplate;
    }

    @RequestMapping("/sms")
    public void getSmsCode(String tel) {
        //String code = String.valueOf(new Random().nextInt(899999) + 100000);//生成短信验证码
        String code = "123456";
        String key = "PhoneCode"+tel;
        stringRedisTemplate.opsForValue().set(key,code,5,TimeUnit.MINUTES);
        //smsUtils.sendSms(tel,code); //真实发送短信验证码工具类
    }

}
